﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Himp.Platform
{
    /// <summary>
    /// 事件消息主题
    /// </summary>
    public class EventMsgTopicService : CrudAppService<EventMsgTopic, EventMsgTopicDto, Guid, EventMsgTopicInput, EventMsgTopicCreateDto, EventMsgTopicUpdateDto>
    {
        private IRepository<EventMsgTopic, Guid> _eventMsgTopicRepository;

        public EventMsgTopicService(IRepository<EventMsgTopic, Guid> eventMsgTopicRepository) : base(eventMsgTopicRepository)
        {
            _eventMsgTopicRepository = eventMsgTopicRepository;
        }

        /// <summary>
        /// 获取消息业务类别
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override async Task<PagedResultDto<EventMsgTopicDto>> GetListAsync(EventMsgTopicInput input)
        {
            var iQuery = await _eventMsgTopicRepository.GetQueryableAsync();

            if (input.Pi == 0)
            {
                var itemsDto = ObjectMapper.Map<List<EventMsgTopic>, List<EventMsgTopicDto>>(iQuery.ToList());

                return new PagedResultDto<EventMsgTopicDto>(itemsDto.Count, itemsDto);
            }
            else
            {
                var totalCount = iQuery.Count();
                var items = iQuery.Page(input.Pi, input.Ps);
                var itemsDto = ObjectMapper.Map<List<EventMsgTopic>, List<EventMsgTopicDto>>(items.ToList());

                return new PagedResultDto<EventMsgTopicDto>(totalCount, itemsDto);
            }
        }
    }
}
